// pages/index/goodsList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 筛选弹出层
    sxShow: false,
    //价格按钮图标转换
    changePrice: false,
    //综合按钮
    selectAll: true,
    //销量按钮
    selectCount: false,
    //价格按钮
    selectPrice: false,
    /**
     * 筛选规格列表
     */
    goodsSpecification: [{
        id: 1,
        title: "品项",
        type: "select",
        list: [{
            id: 1,
            name: "全部",
            isChecked: true,
          },
          {
            id: 2,
            name: "花冠",
            isChecked: false,
          },
          {
            id: 3,
            name: "贝智康",
            isChecked: false,
          },
          {
            id: 4,
            name: "林奇牧场",
            isChecked: false,
          },
          {
            id: 5,
            name: "贝智康A段",
            isChecked: false,
          },
          {
            id: 6,
            name: "贝智康",
            isChecked: false,
          },
          {
            id: 7,
            name: "林奇牧场",
            isChecked: false,
          },
          {
            id: 8,
            name: "A段",
            isChecked: false,
          }

        ]
      },
      {
        id: 2,
        title: "价格区间",
        type: "minmax"
      },
      {
        id: 3,
        title: "品项",
        type: "select",
        list: [{
            id: 1,
            name: "全部",
            isChecked: true,
          },
          {
            id: 2,
            name: "花冠",
            isChecked: false,
          },
          {
            id: 3,
            name: "贝智康",
            isChecked: false,
          },
          {
            id: 4,
            name: "林奇牧场",
            isChecked: false,
          },
          {
            id: 5,
            name: "贝智康A段",
            isChecked: false,
          },
          {
            id: 6,
            name: "贝智康",
            isChecked: false,
          },
          {
            id: 7,
            name: "林奇牧场",
            isChecked: false,
          },
          {
            id: 8,
            name: "A段",
            isChecked: false,
          }

        ]
      },
    ],
    // 筛选重置按钮
    chooseBtn: false,
    //重置判断
    allChecked: true,


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  // 价格按钮转化
  queryPrice: function() {
    this.setData({
      changePrice: !this.data.changePrice,
    })
  },
  //筛选显示
  showSx: function() {
    this.setData({
      sxShow: !this.data.sxShow,
      changePrice: false,
    })
  },
  //筛选-选择种类按钮
  sxChooseBtn: function(e) {
    let that = this;
    let father = e.currentTarget.dataset.father;
    let id = e.currentTarget.dataset.id;
    let goodsSpecification = that.data.goodsSpecification;
    goodsSpecification.forEach(item => {
      if (item.id == father) {
        item.list.forEach(list => {
          if (list.id == id) {
            list.isChecked = !list.isChecked;
          } else {
            list.isChecked = false;
          }
        });
      }
    });
    that.setData({
      allChecked: true,
      goodsSpecification: goodsSpecification
    });

  },
  //筛选-重置按钮事件
  doResetting: function() {
    this.setData({
      chooseBtn: !this.data.chooseBtn,
    });
    let arr = this.data.goodsSpecification;
    arr.forEach(item => {
      if(item.list){
        item.list.forEach(list => {
          this.setData({
            allChecked: false
          })
        });
      }
    });
  },
  //筛选-确定按钮事件
  goConfirm: function() {
    this.setData({
      chooseBtn: !this.data.chooseBtn,
      sxShow: !this.data.sxShow,
      allChecked: true,
    })
  },
  //综合按钮事件
  queryAll: function(e) {
    this.setData({
      selectAll: true,
      selectCount: false,
      selectPrice: false,
      changeScrollTop: 'good-search-select-box',
      changePrice: false,
    });
  },
  //销量按钮事件
  queryCount: function() {
    this.setData({
      selectAll: false,
      selectCount: true,
      selectPrice: false,
      changePrice: false,
    })
  },
  //价格按钮事件
  queryPrice: function() {
    this.setData({
      changePrice: !this.data.changePrice,
      selectAll: false,
      selectCount: false,
      selectPrice: true,
    })
  },



})